package com.example.app.controller;

import com.example.app.dao.LiveLocationDto;
import com.example.app.service.LiveLocationService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/live")
@RequiredArgsConstructor
public class LiveLocationController {
    private final LiveLocationService liveLocationService;

    // 启动或更新实时位置
    @PostMapping("/update")
    public ResponseEntity<Void> updateLocation(@RequestParam Long userId,
                                               @RequestParam double latitude,
                                               @RequestParam double longitude) {
        liveLocationService.updateLocation(userId, latitude, longitude);
        return ResponseEntity.ok().build();
    }

    // 停止共享
    @PostMapping("/stop")
    public ResponseEntity<Void> stopSharing(@RequestParam Long userId) {
        liveLocationService.stopSharing(userId);
        return ResponseEntity.ok().build();
    }

    // 获取好友实时位置
    @GetMapping("/friends")
    public ResponseEntity<List<LiveLocationDto>> getFriendLocations(@RequestParam Long userId) {
        return ResponseEntity.ok(liveLocationService.getFriendsLiveLocations(userId));
    }
}
